/*
 * KiPE.h
 *
 *  Created on: 2013-10-16
 *      Author: WinDDK
 */

#ifndef KIPE_H_
#define KIPE_H_

#include "Utility.h"

class KiPE
{
protected:
    static const ULONG MODULENAMELENGTH = 20;
    static const ULONG SYSTEMPATHLENGTH = 64;
    static const ULONG MODULEPATHLENGTH = 128;
    CHAR mModuleName[MODULENAMELENGTH + 1];
    CHAR mSystemPath[SYSTEMPATHLENGTH + 1];
    CHAR mModulePath[MODULEPATHLENGTH + 1];

    ULONG mNewImageBase;
    PIMAGE_NT_HEADERS mNewImageNtHeader;

    ULONG mOldImageBase;

    BOOLEAN FixRelocTable();
    BOOLEAN FixImportTable();
    BOOLEAN GetExportedRoutineByOrdinal(IN ULONG imageBase, IN ULONG ordinal, OUT PULONG functionAddress);
    BOOLEAN GetExportedRoutineByName(IN ULONG imageBase, IN PCHAR routineName, OUT PULONG functionAddress);
    BOOLEAN GetImageBase(IN PCHAR moduleName, OUT ULONG &imageBase);
    BOOLEAN GetImageDataDirectory(IN ULONG imageBase, IN ULONG TYPE, OUT PULONG pVA, OUT PULONG pSize);
    BOOLEAN GetImageDosHeader(IN ULONG imageBase, OUT PIMAGE_DOS_HEADER & imageDosHeader);
    BOOLEAN GetImageNTHeader(IN ULONG imageBase, OUT PIMAGE_NT_HEADERS & imageNtHeader);

public:
    KiPE();
    virtual ~KiPE();

    BOOLEAN MapFileToMem();
    BOOLEAN GetSystemPath(OUT PCHAR systemPath);
    BOOLEAN LoadModule();
    virtual BOOLEAN GetModulePath() =0;
    virtual BOOLEAN FixModule() = 0;

    ULONG GetNewImageBase();
    ULONG GetOldImageBase();
};

#endif /* KIPE_H_ */

